#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <memory>
#include <cassert>
#include <sys/stat.h>
#include "err.hpp"
#include "http_server.hpp"
#include "protocol.hpp"


void usage(const std::string& proc)
{
    std::cout << "Uasge:\n\t" << proc << " port\n" << std::endl;
}

std::string callback(const std::string& msg)
{
    std::cout << msg << std::endl;
    std::cout << "---------------------------" << std::endl;

    return http_response(http_request(msg)).serialize();
}

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(CMD_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    std::unique_ptr<http_server> tsvr(new http_server(callback, port));
    tsvr->init();
    tsvr->start();

    return 0;
}
